package com.example.administrator.printoutindemo.adapter;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.dds.soap.SoapListener;
import com.dds.soap.SoapParams;
import com.dds.soap.SoapUtil;
import com.dothantech.lpapi.IAtBitmap;
import com.dothantech.lpapi.LPAPI;
import com.dothantech.printer.IDzPrinter;
import com.example.administrator.printoutindemo.R;
import com.example.administrator.printoutindemo.bean.CangKuBean;
import com.example.administrator.printoutindemo.bean.RukuSuccessBean;
import com.example.administrator.printoutindemo.http.SPUtil;
import com.google.gson.Gson;
import com.jess.arms.base.ArmsBaseConstants;
import com.jess.arms.base.BaseConstants;
import com.jess.arms.utils.ArmsUtils;
import com.jess.arms.utils.SharedPreferencesHelper;
import com.qmuiteam.qmui.widget.dialog.QMUIDialog;
import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction;
import com.xiaoxing.zhinenghuacangku.mvp.ui.utils.PrinterUtil;

import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;

import java.util.ArrayList;
import java.util.List;

import com.jess.arms.utils.CProgressDialogUtils;
import me.jessyan.armscomponent.commonsdk.utils.ButtonUtils;

/**
 * Created by Administrator on 2018/9/11.
 */

public class CangkuAdapter extends BaseAdapter {
    protected SharedPreferencesHelper mSharedPreferencesHelper;
    Context context;
    List<CangKuBean> mlist = new ArrayList<>();
    LayoutInflater inflater;
    private int mCurrentDialogStyle = com.qmuiteam.qmui.R.style.QMUI_Dialog;
    private PrinterUtil mPrinterUtil;
    private RukuSuccessBean rukuSuccessBeen;
    private int mStatus = 0;
    private Activity mActivity;

    public CangkuAdapter(Context context, List<CangKuBean> mlist, Activity activity) {
        this.context = context;
        this.mlist = mlist;
        this.mActivity = activity;
        this.inflater = LayoutInflater.from(context);
        mPrinterUtil = new PrinterUtil(context);
        IDzPrinter.Factory.getInstance().init(context, mPrinterUtil.mCallback);
        mSharedPreferencesHelper = SharedPreferencesHelper.getInstance(context);

    }

    public void shua() {
        mlist = new ArrayList<>();
        notifyDataSetInvalidated();
    }

    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public Object getItem(int i) {
        return mlist.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
//        IDzPrinter.Factory.getInstance().init(context, null);
        ViewHolder holder = null;
        if (view == null) {
            view = getInflater().inflate(R.layout.item_cangku, null);
            holder = new ViewHolder();
            holder.tv_bh = view.findViewById(R.id.tv_bh);
            holder.tv_cwmc = view.findViewById(R.id.tv_cwmc);
            holder.tv_cwlx = view.findViewById(R.id.tv_cwlx);
            holder.tv_cwdz = view.findViewById(R.id.tv_cwdz);
            holder.tv_ckbh = view.findViewById(R.id.tv_ckbh);
            holder.tv_cwzt = view.findViewById(R.id.tv_cwzt);
            holder.tv_cwms = view.findViewById(R.id.tv_cwms);
            holder.tv_cwbz = view.findViewById(R.id.tv_cwbz);
            holder.tv_rk = view.findViewById(R.id.tv_rk);
            holder.tv_dyewm = view.findViewById(R.id.tv_dyewm);
            holder.et_beizhu = view.findViewById(R.id.et_beizhu);
            holder.tv_cang_ku = view.findViewById(R.id.tv_cang_ku);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        if (String.valueOf(mlist.get(i).getSpid()) != null) {
            holder.tv_bh.setText(String.valueOf(mlist.get(i).getSpid()));
        }
        if (mlist.get(i).getSpname() != null) {
            holder.tv_cwmc.setText(mlist.get(i).getSpname());
        }
        if (String.valueOf(mlist.get(i).getSptype()) != null) {
            holder.tv_cwlx.setText(String.valueOf(mlist.get(i).getSptype()));
        }
        if (mlist.get(i).getSpadd() != null) {
            holder.tv_cwdz.setText(mlist.get(i).getSpadd());
        }
        if (String.valueOf(mlist.get(i).getSid()) != null) {
            holder.tv_ckbh.setText(String.valueOf(mlist.get(i).getSid()));
        }
        if (mlist.get(i).getSname() != null) {
            holder.tv_cang_ku.setText(mlist.get(i).getSname());
        }
        if (String.valueOf(mlist.get(i).getSpstatus()) != null) {

            switch (mlist.get(i).getSpstatus()) {

                case 0:
                    holder.tv_cwzt.setText("未占");
                    break;
                case 1:
                    holder.tv_cwzt.setText("未满");
                    break;
                case 2:
                    holder.tv_cwzt.setText("已满");
                    break;

            }


        }
        if (mlist.get(i).getSpdes() != null) {
            holder.tv_cwms.setText(mlist.get(i).getSpdes());
        }
        if (mlist.get(i).getSpremark() != null) {
            holder.tv_cwbz.setText(mlist.get(i).getSpremark());
        }
        if (mlist.get(i).getSpstatus() == 2) {
            holder.tv_rk.setVisibility(View.GONE);
        } else {
            holder.tv_rk.setVisibility(View.VISIBLE);
        }

        final ViewHolder finalHolder = holder;
        final ViewHolder finalHolder1 = holder;
        final ViewHolder finalHolder2 = holder;
        holder.tv_rk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (TextUtils.isEmpty(SPUtil.getString(context, "zhaopian1", ""))) {
                    ArmsUtils.makeText(context, "请先拍照");
                    return;
                } else {
                    if (!ButtonUtils.isFastDoubleClick()) {
                        showConfirmMessageDialog(i, finalHolder);
                    } else {
                        ArmsUtils.makeText(context, "10s内请勿重复点击");
                    }

                }

            }
        });
        holder.tv_dyewm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                printQRcode(SPUtil.getString(context, "erweima", ""));
                if (rukuSuccessBeen != null) {

                    if (mSharedPreferencesHelper.getString(BaseConstants.ER_WEI_MA_TYPE).equals("1")) {
                        printQRcode(String.valueOf(rukuSuccessBeen.getMid()), rukuSuccessBeen.getPurchaseid(), rukuSuccessBeen.getMaterial(), rukuSuccessBeen.getNums(), rukuSuccessBeen.getInstoretime(), rukuSuccessBeen.getProid());
                    } else {
//                        printBigQRcode(String.valueOf(rukuSuccessBeen.getMid()), rukuSuccessBeen.getPurchaseid(), rukuSuccessBeen.getMaterial(), rukuSuccessBeen.getNums(), rukuSuccessBeen.getInstoretime(), rukuSuccessBeen.getProid());
                        printBigQRcodeOriention(String.valueOf(rukuSuccessBeen.getMid()), rukuSuccessBeen.getPurchaseid(), rukuSuccessBeen.getMaterial(), rukuSuccessBeen.getNums(), rukuSuccessBeen.getInstoretime(), rukuSuccessBeen.getProid());
                    }
                }

            }
        });
        return view;
    }

    public LayoutInflater getInflater() {
        return inflater;
    }

    public void setInflater(LayoutInflater inflater) {
        this.inflater = inflater;
    }

    private void showConfirmMessageDialog(int i, ViewHolder finalHolder) {
        new QMUIDialog.CheckBoxMessageDialogBuilder(context)
                .setTitle("确认入库")
                .setMessage("入库")
                .setChecked(true)
                .addAction("取消", new QMUIDialogAction.ActionListener() {
                    @Override
                    public void onClick(QMUIDialog dialog, int index) {
                        dialog.dismiss();
                    }
                })
                .addAction("确定", new QMUIDialogAction.ActionListener() {
                    @Override
                    public void onClick(QMUIDialog dialog, int index) {
                        dialog.dismiss();
                        String shuLiang = SPUtil.getString(context, "shuliang", "");
                        if (TextUtils.isEmpty(shuLiang)) {
                            ArmsUtils.makeText(context, "请填写数量");
                            return;
                        }

                        SPUtil.putInt(context, "spid", mlist.get(i).getSpid());
                        SPUtil.putInt(context, "status", mlist.get(i).getSpstatus());
                        SPUtil.putString(context, "remark", finalHolder.et_beizhu.getText().toString());

                        SoapParams params = new SoapParams();
                        params.put("did", String.valueOf(SPUtil.getInt(context, "dids", 0)));
                        params.put("spid", String.valueOf(mlist.get(i).getSpid()));
                        params.put("uid", SPUtil.getString(context, "iduser", ""));
                        params.put("num", shuLiang);
//                map.put("status", String.valueOf(mlist.get(i).getSpstatus()));
                        params.put("status", "1");
                        params.put("remark", finalHolder.et_beizhu.getText().toString());
//                        params.put("imgStr", SPUtil.getString(context, "zhaopian", ""));
                        params.put("imgStr1", SPUtil.getString(context, "zhaopian1", ""));
                        params.put("imgStr2", SPUtil.getString(context, "zhaopian2", ""));
                        params.put("imgStr3", SPUtil.getString(context, "zhaopian3", ""));
                        params.put("imgStr4", SPUtil.getString(context, "zhaopian4", ""));
                        params.put("imgStr5", SPUtil.getString(context, "zhaopian5", ""));
                        params.put("imgStr6", SPUtil.getString(context, "zhaopian6", ""));
                        params.put("imgStr7", SPUtil.getString(context, "zhaopian7", ""));
                        params.put("imgStr8", SPUtil.getString(context, "zhaopian8", ""));
                        params.put("imgStr9", SPUtil.getString(context, "zhaopian9", ""));
                        params.put("imgStr10", SPUtil.getString(context, "zhaopian10", ""));
                        instore(params, finalHolder);
                    }
                })
                .create(mCurrentDialogStyle).show();
    }

    private void printQRcode(String content, String orderNo, String name, String num, String time, String proid) {
        if (mPrinterUtil.selectPrinterCheck()) {

            // 得到 IDzPrinter 对象
            IDzPrinter printer = IDzPrinter.Factory.getInstance();
            // 连接配对的第一个打印机对象
            printer.connect(IDzPrinter.Factory.getFirstPrinter());
            // 创建 IAtBitmap 绘图对象
            IAtBitmap api = IAtBitmap.Factory.createInstance();
            // 开始绘图任务，传入参数(页面宽度, 页面高度)
            api.startJob(48 * 100, 20 * 100);//48, 50
            // 开始一个页面的绘制，绘制二维码
            api.draw2DQRCode(content, 0 * 100, 1 * 100, 15 * 100);//  9, 10, 20,30
            api.drawText("订单号:" + orderNo, 16 * 100, 0 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
            if (name.length() > 15) {
                if (name.substring(15).length() > 20) {
                    api.drawText("核对序号:" + content, 16 * 100, 3 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                    api.drawText("项目编号:" + proid, 16 * 100, 6 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                    api.drawText("物料名称:" + name.substring(0, 15), 16 * 100, 96 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                    api.drawText("" + name.substring(15, 35), 16 * 100, 12 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                    api.drawText("" + name.substring(35), 16 * 100, 15 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//                api.drawText("数量:" + num, 16 * 100, 12 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR);
                    api.drawText("入库时间:" + time, 16 * 100, 18 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                } else {
                    api.drawText("核对序号:" + content, 16 * 100, 3 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                    api.drawText("项目编号:" + proid, 16 * 100, 6 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                    api.drawText("物料名称:" + name.substring(0, 15), 16 * 100, 9 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                    api.drawText("" + name.substring(15), 16 * 100, 12 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//                api.drawText("数量:" + num, 16 * 100, 9 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR);
                    api.drawText("入库时间:" + time, 16 * 100, 15 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                }

            } else {
                api.drawText("核对序号:" + content, 16 * 100, 3 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                api.drawText("项目编号:" + proid, 16 * 100, 6 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                api.drawText("物料名称:" + name, 16 * 100, 9 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//            api.drawText("数量:" + num, 16 * 100, 6 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR);
                api.drawText("入库时间:" + time, 16 * 100, 12 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
            }

            // 结束绘图任务
            api.endJob();
            // 打印
            printer.print(api, null);
        }
    }

    /**
     * 大的纸张 50x50的
     *
     * @param content
     * @param orderNo
     * @param name
     * @param num
     * @param time
     * @param proid
     */
    private void printBigQRcode(String content, String orderNo, String name, String num, String time, String proid) {
        if (mPrinterUtil.selectPrinterCheck()) {

            // 得到 IDzPrinter 对象
            IDzPrinter printer = IDzPrinter.Factory.getInstance();
            // 连接配对的第一个打印机对象
            printer.connect(IDzPrinter.Factory.getFirstPrinter());
            // 创建 IAtBitmap 绘图对象
            IAtBitmap api = IAtBitmap.Factory.createInstance();
            // 开始绘图任务，传入参数(页面宽度, 页面高度)
            api.startJob(48 * 100, 50 * 100);//48, 50
            // 开始一个页面的绘制，绘制二维码
            api.draw2DQRCode(content, 10 * 100, 5 * 100, 25 * 100);//  9, 10, 20,30
            api.drawText("订单号:" + orderNo, 0 * 100, 32 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
            if (name.length() > 25) {
                if (name.substring(25).length() > 20) {
                    api.drawText("核对序号:" + content, 0 * 100, 35 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                    api.drawText("项目编号:" + proid, 0 * 100, 38 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                    api.drawText("物料名称:" + name.substring(0, 15), 0 * 100, 41 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                    api.drawText("" + name.substring(15, 35), 0 * 100, 44 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                    api.drawText("" + name.substring(35), 0 * 100, 47 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//                api.drawText("数量:" + num, 16 * 100, 12 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR);
                    api.drawText("入库时间:" + time, 0 * 100, 50 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                } else {
                    api.drawText("核对序号:" + content, 0 * 100, 35 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                    api.drawText("项目编号:" + proid, 0 * 100, 38 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                    api.drawText("物料名称:" + name.substring(0, 15), 0 * 100, 41 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                    api.drawText("" + name.substring(15), 0 * 100, 44 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//                api.drawText("数量:" + num, 16 * 100, 9 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR);
                    api.drawText("入库时间:" + time, 0 * 100, 47 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                }

            } else {
                api.drawText("核对序号:" + content, 0 * 100, 35 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                api.drawText("项目编号:" + proid, 0 * 100, 38 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                api.drawText("物料名称:" + name, 0 * 100, 41 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//            api.drawText("数量:" + num, 16 * 100, 6 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR);
                api.drawText("入库时间:" + time, 0 * 100, 44 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
            }

            // 结束绘图任务
            api.endJob();
            // 打印
            printer.print(api, null);
        }
    }
    private  void printBigQRcodeOriention(String content, String orderNo, String name, String num, String time, String proid) {

        // 得到 IDzPrinter 对象
        IDzPrinter printer = IDzPrinter.Factory.getInstance();
        // 连接配对的第一个打印机对象
        printer.connect(IDzPrinter.Factory.getFirstPrinter());
        // 创建 IAtBitmap 绘图对象
        IAtBitmap api = IAtBitmap.Factory.createInstance();
        // 开始绘图任务，传入参数(页面宽度, 页面高度)
        api.setItemHorizontalAlignment(LPAPI.ItemAlignment.LEFT);
        api.setItemOrientation(180);

        api.startJob(50 * 100, 50 * 100);//48, 50
//        api.setItemOrientation(180);

        // 开始一个页面的绘制，绘制二维码
        if (name.length() > 19) {
            if (name.substring(19).length() > 23) {
                api.drawText("入库时间:" + time, 46 * 100, 4 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                api.drawText("" + name.substring(42), 46 * 100, 7 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                api.drawText("" + name.substring(19, 42), 46 * 100, 10 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                api.drawText("物料名称:" + name.substring(0, 19), 46 * 100, 13 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                api.drawText("项目编号:" + proid, 46 * 100, 16 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                api.drawText("核对序号:" + content, 46 * 100, 19 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//                api.drawText("数量:" + num, 16 * 100, 12 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR);
                api.drawText("订单号:" + orderNo, 46 * 100, 22 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                api.draw2DQRCode(content, 14 * 100, 23 * 100, 17 * 100);//  9, 10, 20,30
            } else {
                api.drawText("入库时间:" + time, 46 * 100, 4 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                api.drawText("" + name.substring(19), 46 * 100, 7 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                api.drawText("物料名称:" + name.substring(0, 19), 46 * 100, 10 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                api.drawText("项目编号:" + proid, 46 * 100, 13 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                api.drawText("核对序号:" + content, 46 * 100, 16 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//                api.drawText("数量:" + num, 16 * 100, 9 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR);
                api.drawText("订单号:" + orderNo, 46 * 100, 19 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
                api.draw2DQRCode(content, 14 * 100, 20 * 100, 20 * 100);//  9, 10, 20,30
            }

        } else {
            api.drawText("入库时间:" + time, 46 * 100, 4 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
            api.drawText("物料名称:" + name, 46 * 100, 7 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
            api.drawText("项目编号:" + proid, 46 * 100, 10 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
            api.drawText("核对序号:" + content, 46 * 100, 13 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//            api.drawText("数量:" + num, 16 * 100, 6 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR);
            api.drawText("订单号:" + orderNo, 46 * 100, 16 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
            api.draw2DQRCode(content, 14 * 100, 17 * 100, 20 * 100);//  9, 10, 20,30
        }

        // 结束绘图任务
        api.endJob();
        // 打印
        printer.print(api, null);

    }
    /**
     * @param
     * @return
     * @method
     * @description 入库  方法InstoreMp 改为  InstoreActualAutoForAndroid   改为  Instore  改为 InstoreMp
     * @date: 2020/7/13 0013 11:31
     * @update 2020/07/14 15:37
     * @author: 小星
     */
    private void instore(SoapParams params, ViewHolder finalHolder) {

        CProgressDialogUtils.showProgressDialog(mActivity, "入库中...");
        String methodName = "InstoreMp";

        /**
         * 请求
         */
        SoapUtil.getInstance(context).callEntry(getUrl(), BaseConstants.NAME_SPACE, methodName, params, new SoapListener() {
            @Override
            public void onSuccess(int statusCode, SoapObject object) {
                CProgressDialogUtils.cancelProgressDialog(mActivity);

                String result = object.getProperty(methodName + "Result").toString();
                if (result != null && !result.equals("[]") && !result.equals("anyType{}") && !result.equals("Error") && !result.equals("-100")) {
                    if (result.equals("-1")) {
                        Toast.makeText(context, "该物料已入库，请不要重复入库", Toast.LENGTH_SHORT).show();
                    } else if (result.equals("0")) {
                        Toast.makeText(context, "入库失败！！！", Toast.LENGTH_SHORT).show();
                    } else {
                        finalHolder.tv_rk.setText("入库成功");
                        Log.e("返回的二维码=============", result);

                        rukuSuccessBeen = new Gson().fromJson(result, RukuSuccessBean.class);

                        SPUtil.putString(context, "erweima", String.valueOf(rukuSuccessBeen.getMid()));
                        SPUtil.putString(context, "shuliang", "");
                        AlertDialog.Builder builder = new AlertDialog.Builder(context);
                        builder.setTitle("提示");
                        builder.setMessage("请打印二维码！！！");
                        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
//                                    printQRcode(SPUtil.getString(context, "erweima", ""));
//                                            printQRcode(String.valueOf(rukuSuccessBeen.getMid()), rukuSuccessBeen.getPurchaseid(), rukuSuccessBeen.getMaterial(), rukuSuccessBeen.getNums(), rukuSuccessBeen.getInstoretime(), rukuSuccessBeen.getProid());
                                if (mSharedPreferencesHelper.getString(BaseConstants.ER_WEI_MA_TYPE).equals("1")) {
                                    printQRcode(String.valueOf(rukuSuccessBeen.getMid()), rukuSuccessBeen.getPurchaseid(), rukuSuccessBeen.getMaterial(), rukuSuccessBeen.getNums(), rukuSuccessBeen.getInstoretime(), rukuSuccessBeen.getProid());
                                } else {
//                                    printBigQRcode(String.valueOf(rukuSuccessBeen.getMid()), rukuSuccessBeen.getPurchaseid(), rukuSuccessBeen.getMaterial(), rukuSuccessBeen.getNums(), rukuSuccessBeen.getInstoretime(), rukuSuccessBeen.getProid());
                                    printBigQRcodeOriention(String.valueOf(rukuSuccessBeen.getMid()), rukuSuccessBeen.getPurchaseid(), rukuSuccessBeen.getMaterial(), rukuSuccessBeen.getNums(), rukuSuccessBeen.getInstoretime(), rukuSuccessBeen.getProid());
                                }
                                Log.e("入库==========", SPUtil.getString(context, "erweima", ""));
//                                    Intent intent = new Intent(context, MainActivity.class);
//                                    context.startActivity(intent);
                            }
                        });
                        finalHolder.tv_dyewm.setVisibility(View.VISIBLE);
                        builder.show();
                    }
                } else {
                    ArmsUtils.makeText(context, "入库失败");
                }

            }

            @Override
            public void onFailure(int statusCode, String content, Throwable error) {
                CProgressDialogUtils.cancelProgressDialog(mActivity);
                ArmsUtils.makeText(context, error.getMessage());

            }

            @Override
            public void onFailure(int statusCode, SoapFault fault) {
                CProgressDialogUtils.cancelProgressDialog(mActivity);

            }
        }, getAapiUserName(), getApiPwd());

    }

    protected String getUrl() {
        return "http://" + mSharedPreferencesHelper.getString(ArmsBaseConstants.IP) + ":"
                + mSharedPreferencesHelper.getString(ArmsBaseConstants.PORT)
                + "/StoreService.asmx";
    }

    protected String getAapiUserName() {
        return mSharedPreferencesHelper.getString(BaseConstants.API_USER_NAME);
    }

    protected String getApiPwd() {
        return mSharedPreferencesHelper.getString(BaseConstants.API_PWD);
    }

    private void showMenuDialog() {
        final String[] items = new String[]{"未满", "已满"};
        new QMUIDialog.MenuDialogBuilder(context)
                .addItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
//                        Toast.makeText(context, "你选择了 " + items[which], Toast.LENGTH_SHORT).show();
                        dialog.dismiss();
                        if (items[which].equals("未满")) {
                            mStatus = 1;
                        } else if (items[which].equals("已满")) {
                            mStatus = 2;
                        }
                    }
                })
                .create(mCurrentDialogStyle).show();
    }

    public void addAll(List<CangKuBean> cangku) {
        mlist.addAll(cangku);
        notifyDataSetChanged();
    }

    private void printQRcode(String content) {
        if (mPrinterUtil.selectPrinterCheck()) {

            // 得到 IDzPrinter 对象
            IDzPrinter printer = IDzPrinter.Factory.getInstance();
            // 连接配对的第一个打印机对象
            printer.connect(IDzPrinter.Factory.getFirstPrinter());
            // 创建 IAtBitmap 绘图对象
            IAtBitmap api = IAtBitmap.Factory.createInstance();
            // 开始绘图任务，传入参数(页面宽度, 页面高度)
            api.startJob(48 * 100, 20 * 100);//48, 50
            // 开始一个页面的绘制，绘制二维码
            api.draw2DQRCode(content, 9 * 100, 0 * 100, 15 * 100);//  9, 10, 20,30
            // 结束绘图任务
            api.endJob();
            // 打印
            printer.print(api, null);
        }

    }

    class ViewHolder {
        TextView tv_bh, tv_cwmc, tv_cwlx, tv_cwdz, tv_ckbh, tv_cwzt, tv_cwms, tv_cwbz, tv_rk, et_beizhu, tv_dyewm, tv_cang_ku;
    }

}
